APP_NAME=demo
PROTO_NAME=bs$(APP_NAME).pb

TARGET=gtsoa.bs$(APP_NAME).s
SOURCES=$(wildcard *.go)
PROTO_TARGETS=$(abspath ./bs$(APP_NAME)pb/$(PROTO_NAME).go)
GOOGLEAPI_TARGETS=$(abspath $(GOPATH)/src/github.com/googleapis/googleapis)
GTSOA=$(abspath ../)

.PHONY: proto serve

serve: $(TARGET)
	./$(TARGET) serve --config config.yml

proto: $(PROTO_TARGETS)

%.pb.go: %.proto
	cd $(dir $<) && \
	protoc -I$(GOOGLEAPI_TARGETS) -I$(GTSOA) -I. --include_imports --include_source_info  --go_out=plugins=grpc:$(GOPATH)/src --descriptor_set_out=$(PROTO_NAME)    ./*.proto

$(TARGET): clean proto fmt
	go build -o $@ $(SOURCES)

db-sync: $(TARGET)
	./$(TARGET) db-sync --config config.yml

fmt:
	go vet ./...
	go fmt ./...

debug: start-dockers 

start-dockers: $(TARGET) stop-dockers
	docker-compose -f ./bsdemosoa/docker-compose.yml up -d

stop-dockers:
	docker-compose -f ./bsdemosoa/docker-compose.yml down -v

log-dockers:
	docker-compose -f ./bsdemosoa/docker-compose.yml logs -f

clean:
	go clean
	rm -rf $(TARGET)

commit:
	git commit -a

push:
	git push -u origin master
